/*
 * @Author: your name
 * @Date: 2020-09-09 14:23:39
 * @LastEditTime: 2020-09-22 11:12:13
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \PipeOneMap_WebClient\src\app\g2share\component\g2-stack\g2-stack.component.ts
 */
import { Component, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core';
import { v4 as uuidv4 } from 'uuid';
@Component({
  selector: 'app-g2-stack',
  templateUrl: './g2-stack.component.html',
  styleUrls: ['./g2-stack.component.scss']
})
export class G2StackComponent implements OnInit, OnChanges {
  @Input() data = null;
  id = uuidv4();
  charts = null;
  constructor() { }

  ngOnInit() {
  }
  configureChart(chart) {
    this.charts = chart;
    this.charts.data(this.data);
    this.charts.scale('value', {
      nice: true,
    });
    this.charts.tooltip({
      shared: true,
      showMarkers: false,
    });

    this.charts
      .interval()
      .position('name*value')
      .color('type')
      .adjust('stack').size(26);

    this.charts.interaction('active-region');

    this.charts.render();
  }
  ngOnChanges(changes: SimpleChanges) {
    if (this.charts){
      this.charts.changeData(changes.data.currentValue);
      this.charts.render();
    }
  }
}
